package com.example.lanqiaodemo1.JavaTest8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class getInformation {

    static ArrayList<Student> studentsList = new ArrayList<>();


    public static void getStudentInfoById() {
        System.out.println("请输入你要查询的学号");
        Scanner scanner = new Scanner(System.in);
        long id = scanner.nextLong();
        for (Student student : studentsList) {
            if (id == student.getId()) {
                System.out.println(student);
                return;
            }
        }
        System.out.println("根据学号，没有查找到此人");
    }

    //    获取用户信息通过name
    public static void getStudentInfoByName() {
        System.out.println("请输入用户的姓名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        for (Student student : studentsList) {
            if (student.getName().equals(name)) {
                System.out.println(student);
                return;
            }
        }
        System.out.println("根据姓名，没有查找到此人");
    }


    public static void getAllStudentSumScoreAndAverageScore() {
        for (Student student : studentsList) {
            int sum = 0;
            int average = 0;
            sum += student.getScore().get("英语");
            sum += student.getScore().get("计算机");
            System.out.println(student.getName() + "的总分是" + sum + "  " + student.getName() + "的平均分是" + sum / 2);
        }
    }

//    public static void getStudentInfoByAverageDesc() {
//        //获取用户的平均分 从大到小进行排序
//        Collections.sort(studentsList, (o1, o2) -> (int) (o2.getAverageScore() - o1.getAverageScore()));
//        for (Student student : studentsList) {
//            System.out.println(student);
//        }
//    }

    //录入学生信息
//    public static void GetInfornation() {
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        Student student = new Student();
        HashMap<String, Double> map = new HashMap<>();
        System.out.println("请输入学生学号：");
        student.setId(sc.nextLong());
        System.out.println("请输入学生姓名：");
        String name = sc.next();
        student.setName(name);
        System.out.println("请输入学生性别：");
        String sex = sc.next();
        student.setSex(sex);
        //
        System.out.println("请输入学生计算机成绩：");
        map.put("计算机", sc.nextDouble());
        System.out.println("请输入学生英语成绩：");
        map.put("英语", sc.nextDouble());
        student.setScore(map);
        System.out.println(student.getScore().get("英语"));
        studentsList.add(student);
        System.out.println("录入成功！");
    }


}
